package com.grm.controller;

import com.grm.entity.Mail;
import com.grm.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/mail")
public class MailController {
    @Autowired
    private MailService mailService;

    @PostMapping("/str")
    public String strMail(@RequestBody Mail mail){
        try {
            mailService.sendTextMail(mail);
        } catch (Exception e) {
            return "failed";
        }
        return "success";
    }

//    @PostMapping("/html")
//    public String htmlMail(@RequestBody Mail mail){
//        try {
//            Map<String,Object> map = new HashMap<>();
//            map.put("收入证明模板.pdf","D:\\收入证明模板.pdf");
//            mail.setAttachment(map);
//            mailService.sendHtmlMail(mail,true);
//        } catch (Exception e) {
//            return "failed";
//        }
//        return "success";
//    }
//
//
//    @PostMapping("/template")
//    public String templateMail(@RequestBody Mail mail){
//        try {
//            Map<String,Object> map = new HashMap<>();
//            map.put("username","grm");
//            mail.setAttachment(map);
//            mailService.sendTemplateMail(mail);
//        } catch (Exception e) {
//            return "failed";
//        }
//        return "success";
//    }
}
